home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
207_01
/
checkd.c
< prev
next >
Wrap
Text File
|
1980-01-01
|
20KB
|
592 lines
/* checkd.c -- 5th source file for check register program */
/* copyright (c) 1986 by Jim Woolley and WoolleyWare, San Jose, CA */
/* vers. 1.0, 12/85 thru 5/86
*/
/* this file contains:
* delete()
* undo()
* insert()
* ctrlqork()
* erase( c)
* abandon()
* save()
* reconcile()
* abreviations()
* print()
* order()
* reorder( f)
* datemax( md, d)
*/
#include "a:checks.h"
delete() /* delete Entry[ Recno] */
{
int r;
if ( Recno > Maxentry)
return;
if ( isibbf( Recno))
{
prompt( "Cannot delete ");
puts( BBF);
waitesc();
return;
}
r = Recno - First + HEAD;
movmem( &Entry[ Recno], &Entryundo, RECSIZ);
Modified = Ctrlyundo = TRUE;
if ( Savrecno == Recno)
Savrecno = -1;
else if ( Savrecno > Recno)
--Savrecno;
if ( Recno < Maxentry)
movmem( &Entry[ Recno + 1], &Entry[ Recno], ( Maxentry - Recno)*RECSIZ);
--Maxentry;
if ( Maxentry < 0)
{
First = 0;
Last = Maxentry = -1;
}
else First = min( First, ( Last = min( Last, Maxentry)));
dellin( r);
update( Recno);
if ( Recno > Maxentry)
Field = 0;
putcursor( Recno, Field);
}
undo() /* undo delete for Entry[ Recno] */
{
if ( Ctrlyundo && insert())
{
movmem( &Entryundo, &Entry[ Recno], RECSIZ);
putrecord( Recno);
update( Recno);
putcursor( Recno, Field);
}
}
insert() /* insert Entry[ Recno] */
{ /* return TRUE if successful */
int i;
if ( Maxentry == ( ENTRYSIZE - 1))
{
prompt( "Number of entries is maximum allowed");
waitesc();
return ( FALSE);
}
if ( Recno <= Maxentry)
{
i = Maxentry - Recno + 1;
movmem( &Entry[ Recno], &Entry[ Recno + 1], i*RECSIZ);
movmem( &Balance[ Recno], &Balance[ Recno + 1], i*sizeof( Balance[ 0]));
}
if ( Savrecno >= Recno)
++Savrecno;
++Maxentry;
newentry( Recno); /* Modified will be set TRUE */
Last = min(( Last + 1), ( First + LAST));
inslin( Recno - First + HEAD);
putcursor( Recno, Field);
return ( TRUE);
}
ctrlqork( c) /* process CTRLQ or CTRLK command */
char c;
{
char n;
int i;
cursorto( 0, 2);
n = putnext();
if ( c == CTRLQ) /* process CTRLQ command */
{
switch ( n)
{
case 'R':
gotop();
break;
case 'C':
gobottom();
break;
case 'D':
if ( Recno > Maxentry)
break;
Character = PAYEESIZE; /* putcursor() will readjust */
putcursor( Recno, ( Field = MAXFIELD - 1));
break;
case 'S': case 'H':
Character = 0;
putcursor( Recno, ( Field = 0));
break;
case 'E':
putcursor(( Recno = First), Field);
break;
case 'X':
Recno = min(( Maxentry + 1), ( First + ( LAST - 1)));
if ( Recno > Maxentry)
Field = 0;
putcursor( Recno, Field);
break;
case 'Y': case DEL: case ( CTRL_ + CTRLTOA):
if ( Field == PAYFIELD)
{
strcpy( Savpayee, Entry[ Recno].payee);
Savrecno = Recno;
putcursor( Recno, Field);
erase( n);
}
break;
case 'W': case 'Z':
goupdown( n);
break;
default:
putchar( BEL);
break;
}
}
else /* process CTRLK command */
{
switch ( n)
{
case 'O':
order( 0);
break;
case 'D': case 'X':
done(); /* never returns */
break;
case 'S':
save();
break;
case 'Q':
abandon(); /* may not return */
break;
case 'R':
reconcile();
break;
case 'A':
abreviations();
break;
case 'P':
print();
break;
default:
putchar( BEL);
break;
}
}
}
erase( c) /* erase payee left or right */
char c;
{
char *p, *q;
int count;
q = Entry[ Recno].payee;
p = q + Character;
if ( c == 'Y')
{
count = strlen( p);
*p = '\0';
}
else if ( !Character)
return;
else
{
strcpy( q, p);
count = Character;
Character = 0;
putcursor( Recno, Field);
puts( q);
}
while ( count--)
putchar( PAYEEFILL);
Modified = TRUE;
}
abandon() /* abandon without resave */
{
if ( Modified)
{
prompt( "Abandon without saving changes (Y/N)? ");
if ( getyesno( NO))
aexit();
}
else
{
prompt( "Abandoning unchanged file");
aexit();
}
}
save() /* save entries and continue */
{
prompt( ""); /* clear prompt line */
if ( savedat()) /* if error */
return;
waitesc(); /* else, wait for recognition */
Modified = FALSE;
}
reconcile() /* display summary by category */
{
char c, *spaces, *sh, *ss, scroll, nbr[ DEL];
int i, j, count, lines, firstline, lastline, maxline;
struct
{
struct calendar maxdate;
char sumcategory;
struct money beginbal, clrcheck, clrdeposit, allcheck, alldeposit;
} sum, *a, *start;
struct record *e;
struct money *m, clrendbal, allendbal;
spaces = " ";
sh =
"-------- -------- -------- -------- -------- -------- --------";
ss = "-------- - ";
prompt( "");
setmem( nbr, DEL, 0); /* initialize */
for ( j = 0; j <= Maxentry; ++j) /* count number in each category */
++nbr[ Entry[ j].category & 0x7f];
lines = 0;
for ( i = ' '; i < DEL; ++i) /* count separate categories, then */
if ( nbr[ i]) /* allocate space for each */
++lines;
if ( !lines)
return;
if ( !( a = start = alloc( lines*sizeof( *a))))
{
prompt( "Insufficient memory to reconcile all categories");
waitesc();
return;
}
recheading( ss, sh);
setmem( &sum, sizeof( sum), 0); /* initialize */
setmem( a, ( lines*sizeof( *a)), 0);
for ( i = ' '; i < DEL; ++i) /* summarize each category */
{
if ( !nbr[ i]) /* if category does not exist */
continue; /* next category */
a->sumcategory = i;
count = 0;
for ( j = 0; j <= Maxentry; ++j)
{ /* loop thru entries */
e = &Entry[ j];
if ((( c = e->category) & 0x7f) != i)
continue; /* next entry */
datemax( &( a->maxdate), &( e->date));
m = &( e->amount);
if ( c & 0x80) /* if a BBF entry